package action;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletResponse;

import org.apache.struts2.ServletActionContext;

import service.tAverageDateService;
import service.tDeviceService;
import entity.tDevice;

public class SearchtAverageDateAction
{
    private String deviceId;
    
    private String startime;
    
    private String endtime;
    
    private String deviceName;
    
    private int mark;
    
    private String place;
    
    private tAverageDateService tAverageDateService;
    
    private tDeviceService tdeviceService;
    
    public String search()
        throws IOException
    {
        List<tDevice> list = tdeviceService.searchById(deviceId);
        this.setDeviceName(list.get(0).getDeviceName());
        this.setPlace(list.get(0).getPlace());
        return "success";
    }
    
    public String searchTime()
        throws IOException
    {
        ServletResponse response = ServletActionContext.getResponse();
        response.setCharacterEncoding("utf-8");
        PrintWriter out = response.getWriter();
        String data = tAverageDateService.getDataByTime(startime, endtime, mark, deviceId);
        out.write(data);
        out.flush();
        out.close();
        return null;
    }
    
    public String getDate()
        throws IOException
    {
        
        ServletResponse response = ServletActionContext.getResponse();
        response.setCharacterEncoding("utf-8");
        PrintWriter out = response.getWriter();
        String getX = tAverageDateService.getX(startime, endtime);
        out.write(getX);
        out.flush();
        out.close();
        return null;
    }
    
    public String getDeviceId()
    {
        return deviceId;
    }
    
    public void setDeviceId(String deviceId)
    {
        this.deviceId = deviceId;
    }
    
    public String getStartime()
    {
        return startime;
    }
    
    public void setStartime(String startime)
    {
        this.startime = startime;
    }
    
    public String getEndtime()
    {
        return endtime;
    }
    
    public void setEndtime(String endtime)
    {
        this.endtime = endtime;
    }
    
    public int getMark()
    {
        return mark;
    }
    
    public void setMark(int mark)
    {
        this.mark = mark;
    }
    
    public tAverageDateService gettAverageDateService()
    {
        return tAverageDateService;
    }
    
    public void settAverageDateService(tAverageDateService tAverageDateService)
    {
        this.tAverageDateService = tAverageDateService;
    }
    
    public String getDeviceName()
    {
        return deviceName;
    }
    
    public void setDeviceName(String deviceName)
    {
        this.deviceName = deviceName;
    }
    
    public String getPlace()
    {
        return place;
    }
    
    public void setPlace(String place)
    {
        this.place = place;
    }
    
    public tDeviceService getTdeviceService()
    {
        return tdeviceService;
    }
    
    public void setTdeviceService(tDeviceService tdeviceService)
    {
        this.tdeviceService = tdeviceService;
    }
    
}
